//
//  ZPAlertView.m
//  NothingIsImpossible
//
//  Created by hztuen on 15/8/19.
//  Copyright (c) 2015年 hztuen. All rights reserved.
//

#import "ZPAlertView.h"

@implementation ZPAlertView

@synthesize delegate;
 
//如果这个类是基于UIControllView的话。可以直接在ViewDidLoad里面调用。那么效果也是一样的  这里就相当于别的类里调用这个方法。起到激活的作用
 
-(void)setFrame:(CGRect)frame
{
    CGSize size=[UIScreen mainScreen].bounds.size;
    CGRect newFrame = CGRectMake(0,0,size.width,size.height);
    [super setFrame:newFrame];
}

-(id)initWithMessage:(NSString *)str
{
    if (self =[super init])
    {
        CGSize size=[UIScreen mainScreen].bounds.size;
        UIImageView *bgIV=[[UIImageView alloc]initWithFrame:self.frame];
        bgIV.backgroundColor=[UIColor blackColor];
        bgIV.alpha=0.1;
        [self addSubview:bgIV];
        
        CGRect newFrame = CGRectMake(size.width/2-100,size.height/2-50,200,80);
        UIView *view=[[UIView alloc]initWithFrame:newFrame];
        [self addSubview:view];
        view.backgroundColor=[UIColor whiteColor];
        view.layer.masksToBounds=YES;
        view.layer.cornerRadius=5;
        
        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 50)];
        label.textColor=[UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1];
        label.text=str;
        label.font=[UIFont systemFontOfSize:13];
        
        label.textAlignment=NSTextAlignmentCenter;
        [view addSubview:label];
        UIButton* button1=[[UIButton alloc]initWithFrame:CGRectMake(0, 50, 99, 30)];
        [button1 setTitle:@"取消" forState:UIControlStateNormal];
        button1.titleLabel.font=[UIFont systemFontOfSize:13];
        [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button1 setBackgroundColor:[UIColor colorWithRed:1 green:0.5 blue:0.5 alpha:1]];
        [button1 addTarget:self action:@selector(cancelClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [view addSubview:button1];
        UIButton* button2=[[UIButton alloc]initWithFrame:CGRectMake(101,50, 100, 30)];
        [button2 setTitle:@"确定" forState:UIControlStateNormal];
        button2.titleLabel.font=[UIFont systemFontOfSize:13];
        
        [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button2 setBackgroundColor:[UIColor colorWithRed:1 green:0.5 blue:0.5 alpha:1]];
        [view addSubview:button2];
        button2.titleLabel.textColor=[UIColor whiteColor];
        [button2 addTarget:self action:@selector(sureClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(IBAction)cancelClick:(id)sender
{
    [self removeFromSuperview];
}

-(IBAction)sureClick:(id)sender
{
    [delegate clicked:self];
    [self removeFromSuperview];
}

@end
